package com.easyattendance.model;


import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="TBL_ASSIGNMENT_STUDENT")
@IdClass(AssignmentStudentPK.class)
/*@AssociationOverrides({
	@AssociationOverride(name = "pk.assignment", 
		joinColumns = @JoinColumn(name = "assignment_id")),
	@AssociationOverride(name = "pk.student", 
		joinColumns = @JoinColumn(name = "student_id")) })*/
public class AssignmentStudent {
	
	@Id
	@GenericGenerator(name="stud_roll_no",strategy="foreign")
	@Column(name="stud_roll_no",length=3,nullable=false)
	private int stud_roll_no;
	
	@Id
	@GenericGenerator(name="assignment_id",strategy="foreign")
	@Column(name="assignment_id",length=15,nullable=false)
	private String assignment_id;
	
	@Id
	@GenericGenerator(name="subject_id",strategy="foreign")
	@Column(name="subject_id",length=6,nullable=false)
	private String subject_id;
	
	@Id
	@GenericGenerator(name="class_id",strategy="foreign")
	@Column(name="class_id",length=15,nullable=false)
	private String class_id;
	
	@ManyToOne
	@JoinColumns({
		@JoinColumn(name="assignment_id", insertable=false, updatable=false,referencedColumnName="assignment_id"),
		//@JoinColumn(name="stud_roll_no", insertable=false,updatable=false,referencedColumnName="stud_roll_no"),
		@JoinColumn(name="subject_id", insertable=false,updatable=false,referencedColumnName="subject_id"),
		@JoinColumn(name="class_id", insertable=false,updatable=false,referencedColumnName="class_id")
	})
	private Assignment assignment;
	
	@ManyToOne
	@JoinColumns({
	@JoinColumn(name="stud_roll_no", insertable=false,updatable=false,referencedColumnName="stud_roll_no"),
	@JoinColumn(name="class_id", insertable=false,updatable=false,referencedColumnName="class_id")
	})
	private Student student;  
	
	/*@ManyToOne
	@JoinColumn(name="subject_id", insertable=false,updatable=false,referencedColumnName="subject_id")
    private Subject subject;
	
	@ManyToOne
	@JoinColumn(name="class_id", insertable=false,updatable=false,referencedColumnName="class_id")
    private Class classObj;  */
	
	@Column(name="submission_status",length=1)
	private String submission_status;
	
	@Column(name="submitted_date",nullable=false)
	private Date submitted_date;
	
	@Column(name="marks_received",length=3)
	private int marks_received;
	
	
	
	public int getStud_roll_no() {
		return stud_roll_no;
	}

	public void setStud_roll_no(int stud_roll_no) {
		this.stud_roll_no = stud_roll_no;
	}

	public String getAssignment_id() {
		return assignment_id;
	}

	public void setAssignment_id(String assignment_id) {
		this.assignment_id = assignment_id;
	}

	public String getSubject_id() {
		return subject_id;
	}

	public void setSubject_id(String subject_id) {
		this.subject_id = subject_id;
	}

	public String getClass_id() {
		return class_id;
	}

	public void setClass_id(String class_id) {
		this.class_id = class_id;
	}

	public Assignment getAssignment() {
		return assignment;
	}

	public void setAssignment(Assignment assignment) {
		this.assignment = assignment;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public String getSubmission_status() {
		return submission_status;
	}

	public void setSubmission_status(String submission_status) {
		this.submission_status = submission_status;
	}

	public Date getSubmitted_date() {
		return submitted_date;
	}

	public void setSubmitted_date(Date submitted_date) {
		this.submitted_date = submitted_date;
	}

	public int getMarks_received() {
		return marks_received;
	}

	public void setMarks_received(int marks_received) {
		this.marks_received = marks_received;
	}

	public AssignmentStudent()
	{
		
	}

	public AssignmentStudent(int stud_roll_no, String assignment_id,
			String subject_id, String class_id, String submission_status,
			Date submitted_date, int marks_received) {
		super();
		this.stud_roll_no = stud_roll_no;
		this.assignment_id = assignment_id;
		this.subject_id = subject_id;
		this.class_id = class_id;
		this.submission_status = submission_status;
		this.submitted_date = submitted_date;
		this.marks_received = marks_received;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((assignment_id == null) ? 0 : assignment_id.hashCode());
		result = prime * result
				+ ((class_id == null) ? 0 : class_id.hashCode());
		result = prime * result + stud_roll_no;
		result = prime * result
				+ ((subject_id == null) ? 0 : subject_id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AssignmentStudent other = (AssignmentStudent) obj;
		if (assignment_id == null) {
			if (other.assignment_id != null)
				return false;
		} else if (!assignment_id.equals(other.assignment_id))
			return false;
		if (class_id == null) {
			if (other.class_id != null)
				return false;
		} else if (!class_id.equals(other.class_id))
			return false;
		if (stud_roll_no != other.stud_roll_no)
			return false;
		if (subject_id == null) {
			if (other.subject_id != null)
				return false;
		} else if (!subject_id.equals(other.subject_id))
			return false;
		return true;
	}

	
}
